home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 78 / IOPROG_78.ISO / soft / Codice / da visual basic a c# / service1.asm.cs < prev   
Encoding:
Text File  |  2004-01-30  |  2.3 KB  |  97 lines

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Web;
  7. using System.Web.Services;
  8.  
  9. namespace MathService
  10. {
  11.  
  12.     [WebService(Namespace="http://www.bigatti.it/namespaces")]
  13.     public class GenericStats : System.Web.Services.WebService
  14.     {
  15.  
  16.         public GenericStats()
  17.         {
  18.             //CODEGEN: chiamata richiesta da Progettazione servizi Web ASP.NET.
  19.             InitializeComponent();
  20.         }
  21.  
  22.         #region Codice generato da Progettazione componenti
  23.         
  24.         //Richiesto da Progettazione servizi Web 
  25.         private IContainer components = null;
  26.                 
  27.         /// <summary>
  28.         /// Metodo necessario per il supporto della finestra di progettazione. Non modificare
  29.         /// il contenuto del metodo con l'editor di codice.
  30.         /// </summary>
  31.         private void InitializeComponent()
  32.         {
  33.         }
  34.  
  35.         /// <summary>
  36.         /// Pulire le risorse in uso.
  37.         /// </summary>
  38.         protected override void Dispose( bool disposing )
  39.         {
  40.             if(disposing && components != null)
  41.             {
  42.                 components.Dispose();
  43.             }
  44.             base.Dispose(disposing);        
  45.         }
  46.         
  47.         #endregion
  48.  
  49.         [WebMethod(Description="Calcola una serie di statistiche sulla serie di numeri passata come parametro")]
  50.         public GenericMathData compute( string valueString )
  51.         {
  52.             GenericMathData result = new GenericMathData();
  53.             result.min = 0;
  54.             result.max = 0;
  55.  
  56.             double sum = 0;
  57.             double squaredSum = 0;
  58.  
  59.             char[] delimiters = ";".ToCharArray();
  60.             string[] values = valueString.Split( delimiters );
  61.  
  62.             result.counter = values.Length;
  63.             for( int i = 0; i < result.counter; i++ ) 
  64.             {
  65.                 float value = float.Parse( values[ i ] );
  66.                 
  67.                 sum += value;
  68.                 squaredSum += value * value;
  69.                 
  70.                 result.min = ( value < result.min || i == 0 ) ? value : result.min;
  71.                 result.max = ( value > result.max) ? value : result.max;
  72.             }
  73.  
  74.             result.mean = (float)(sum / result.counter);
  75.             result.standardDeviation = (float)
  76.                 ( Math.Sqrt( squaredSum - ( result.mean * result.mean ) / 
  77.                     (result.counter-1) ) 
  78.             );
  79.             result.coefficientOfVariation =
  80.                 result.standardDeviation / result.mean;
  81.  
  82.             return result;
  83.         }
  84.  
  85.         public struct GenericMathData 
  86.         {
  87.             public float mean;
  88.             public float standardDeviation;
  89.             public float coefficientOfVariation;
  90.             public int counter;
  91.             public float min;
  92.             public float max;
  93.         }        
  94.     }
  95. }
  96.  
  97.